# 当前项目名字，需要修改！
PROJECT_NAME='ModuleManager'

# 编译工程
BINARY_NAME="${PROJECT_NAME}"

BUILD_SWIFT=true

cd ModuleManagerBuild/ModuleManager

INSTALL_DIR=$PWD/../../Pod/Products
rm -fr "${INSTALL_DIR}"
mkdir $INSTALL_DIR
WRK_DIR=build

BUILD_PATH=${WRK_DIR}

DEVICE_DIR=${BUILD_PATH}/Release-iphoneos/${BINARY_NAME}.framework
SIMULATOR_DIR=${BUILD_PATH}/Release-iphonesimulator/${BINARY_NAME}.framework
RE_OS="Release-iphoneos"
RE_SIMULATOR="Release-iphonesimulator"

xcodebuild -configuration "Release" -project "${PROJECT_NAME}.xcodeproj" -scheme "${BINARY_NAME}" -sdk iphoneos clean build CONFIGURATION_BUILD_DIR="${WRK_DIR}/${RE_OS}" LIBRARY_SEARCH_PATHS="./Pods/build/${RE_OS}"
xcodebuild ARCHS=x86_64 ONLY_ACTIVE_ARCH=NO -configuration "Release" -project "${PROJECT_NAME}.xcodeproj" -scheme "${BINARY_NAME}" -sdk iphonesimulator clean build CONFIGURATION_BUILD_DIR="${WRK_DIR}/${RE_SIMULATOR}" LIBRARY_SEARCH_PATHS="./Pods/build/${RE_SIMULATOR}"

echo " It is a test======="
echo "${DEVICE_DIR}"
echo "${SIMULATOR_DIR}"


if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
mkdir -p "${INSTALL_DIR}"


cp -rp "${DEVICE_DIR}" "${INSTALL_DIR}/"

INSTALL_LIB_DIR=${INSTALL_DIR}
mkdir -p "${INSTALL_LIB_DIR}"

lipo -create "${DEVICE_DIR}/${BINARY_NAME}" "${SIMULATOR_DIR}/${BINARY_NAME}" -output "${INSTALL_DIR}/${BINARY_NAME}.framework/${BINARY_NAME}"
if [ $BUILD_SWIFT = true ]
then
cp -rp ${SIMULATOR_DIR}/Modules/${BINARY_NAME}.swiftmodule/*.{swiftmodule,swiftdoc} "$INSTALL_DIR/$BINARY_NAME.framework/Modules/$BINARY_NAME.swiftmodule"

cp -rp ${SIMULATOR_DIR}/Modules/${BINARY_NAME}.swiftmodule/Project/*.swiftsourceinfo "$INSTALL_DIR/$BINARY_NAME.framework/Modules/$BINARY_NAME.swiftmodule/Project"

else
　　echo"NO Swift file for build"
fi

rm -r "${WRK_DIR}"
